package com.evil.enterprise.controller;

import com.evil.application.api.RemoteApplicationGroupService;
import com.evil.application.pojo.dto.group.AddGroupReqDTO;
import com.evil.application.pojo.dto.group.ModifyGroupReqDTO;
import com.evil.common.core.entity.R;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 应用组接口
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/application/group")
public class ApplicationGroupController {

    private final RemoteApplicationGroupService remoteApplicationGroupService;

    /**
     * 新增应用组
     *
     * @param addGroupReqDTO addGroupReqDTO
     * @return R
     */
    @PostMapping("/add")
    public R<?> addGroup(@Validated @RequestBody AddGroupReqDTO addGroupReqDTO) {
        remoteApplicationGroupService.addGroup(addGroupReqDTO);
        return R.success();
    }

    /**
     * 编辑应用组
     *
     * @param modifyGroupReqDTO modifyGroupReqDTO
     * @return R
     */
    @PostMapping("/modify")
    public R<?> modifyGroup(@Validated @RequestBody ModifyGroupReqDTO modifyGroupReqDTO) {
        remoteApplicationGroupService.modifyGroup(modifyGroupReqDTO);
        return R.success();
    }

    /**
     * 删除应用组
     *
     * @param applicationGroupId applicationGroupId
     * @return R
     */
    @PostMapping("/delete")
    public R<?> deleteGroup(@RequestParam("applicationGroupId") Long applicationGroupId) {
        remoteApplicationGroupService.deleteGroup(applicationGroupId);
        return R.success();
    }
}
